package ${controllerPackage};

import ${entityPackage}.${tableInfo.entityName};
import ${servicePackage}.${tableInfo.entityName}Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * ${tableInfo.tableComment?if_exists} - Controller
 * @author CodeGenerator
 * @date ${date?string("yyyy-MM-dd HH:mm:ss")}
 */
@RestController
@RequestMapping("/${tableInfo.camelCaseName}")
public class ${tableInfo.entityName}Controller {

    @Autowired
    private ${tableInfo.entityName}Service ${tableInfo.camelCaseName}Service;

    /**
     * 根据主键查询
     */
    @GetMapping("/{id}")
    public ${tableInfo.entityName} getById(@PathVariable("id") Object id) {
        return ${tableInfo.camelCaseName}Service.getById(id);
    }

    /**
     * 查询所有
     */
    @GetMapping
    public List<${tableInfo.entityName}> listAll() {
        return ${tableInfo.camelCaseName}Service.listAll();
    }

    /**
     * 根据条件查询
     */
    @GetMapping("/list")
    public List<${tableInfo.entityName}> listByCondition(@RequestParam Map<String, Object> condition) {
        return ${tableInfo.camelCaseName}Service.listByCondition(condition);
    }

    /**
     * 保存
     */
    @PostMapping
    public int save(@RequestBody ${tableInfo.entityName} record) {
        return ${tableInfo.camelCaseName}Service.save(record);
    }

    /**
     * 更新
     */
    @PutMapping
    public int update(@RequestBody ${tableInfo.entityName} record) {
        return ${tableInfo.camelCaseName}Service.update(record);
    }

    /**
     * 删除
     */
    @DeleteMapping("/{id}")
    public int delete(@PathVariable("id") Object id) {
        return ${tableInfo.camelCaseName}Service.delete(id);
    }

    /**
     * 批量删除
     */
    @DeleteMapping("/batch")
    public int deleteBatch(@RequestBody List<?> ids) {
        return ${tableInfo.camelCaseName}Service.deleteBatch(ids);
    }

    /**
     * 分页查询
     */
    @GetMapping("/page")
    public List<${tableInfo.entityName}> listByPage(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "10") int pageSize,
            @RequestParam Map<String, Object> condition) {
        return ${tableInfo.camelCaseName}Service.listByPage(pageNum, pageSize, condition);
    }

    /**
     * 统计数量
     */
    @GetMapping("/count")
    public int count(@RequestParam Map<String, Object> condition) {
        return ${tableInfo.camelCaseName}Service.count(condition);
    }
}